package com.api.gbhg.daiyanlu.statement;

import com.alibaba.fastjson.JSON;
import com.api.gbhg.daiyanlu.Dao.TheReportCenterDao;
import com.api.gbhg.liuwenbo.utils.AlgorithmUtil;
import com.api.gbhg.zengping.dao.PropertyManagementCostDao;
import weaver.conn.RecordSet;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

/**
 * 预算执行情况报表
 * Mr.dyl
 */
@Path("/performance")
public class PerformanceReport {
    private PropertyManagementCostDao rmcd=new PropertyManagementCostDao();
    TheReportCenterDao dao = new TheReportCenterDao();
    @POST
    @Path("/getPerformance")
    @Produces(MediaType.APPLICATION_JSON)
    public String getPerformance(Map<String,Object> maps) {
        Integer pageNum = 1;//当前页面
        Integer pageSize = 5;//显示数量
        RecordSet rs = dao.getPerformance(pageNum, pageSize);
        Map<String, Object>[] map = new HashMap[rs.getArray().size()];
        int i = 0;
        while (rs.next()){
            map[i] = new HashMap<String, Object>();
            map[i].put("ysqj",rs.getString("nd"));//预算期间
            RecordSet sbdwRs = rmcd.getSBDWById(rs.getInt("sbdw"));
            sbdwRs.next();
            map[i].put("ysdw", sbdwRs.getString("SUBCOMPANYNAME"));//预算单位
            RecordSet sbks = rmcd.getSBKSById(rs.getInt("sbks"));
            sbks.next();
            map[i].put("ysbm",sbks.getString("departmentmark"));//预算部门
            map[i].put("syky",rs.getString("syed"));//剩余可用(万元)
            map[i].put("zxb", AlgorithmUtil.getRealTimeImplementRate(rs.getDouble("syed"), rs.getDouble("ze")));//执行比
            i++;
        }
        com.api.gbhg.zengping.page.PageInfo<String> pageInfo = new com.api.gbhg.zengping.page.PageInfo<>();
        int num = dao.getStatementCount();
        pageInfo.setPageNum(pageNum);
        pageInfo.setPageSize(pageSize);
        pageInfo.setTotal(num);
        pageInfo.setList(map);
        return JSON.toJSONString(pageInfo);
    }
}
